# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Levente Polyak <anthraxx@archlinux.org>
# Contributor: Pierre Schmitz <pierre@archlinux.de>

pkgbase=zlib
pkgname=(zlib minizip)
epoch=1
pkgver=1.3.1
pkgrel=1
pkgdesc='Compression library implementing the deflate compression method found in gzip and PKZIP'
arch=(loong64 x86_64)
license=(Zlib)
url="https://www.zlib.net/"
options=(
  staticlibs  # needed by binutils testsuite
  debug
)
source=(https://github.com/madler/zlib/releases/download/v$pkgver/$pkgname-$pkgver.tar.xz{,.asc})
sha512sums=('1e8e70b362d64a233591906a1f50b59001db04ca14aaffad522198b04680be501736e7d536b4191e2f99767e7001ca486cd802362cca2be05d5d409b83ea732d'
            'SKIP')
b2sums=('42d109223801a493de6d52e7343403d7fc3234a6ca816425fe41ac9c18019b01b93841acd28a235e99f2256a6a17f93624e96b2ddb58d588c8190a6bedb82910'
        'SKIP')
validpgpkeys=('5ED46A6721D365587791E2AA783FCD8E58BCAFBA')  # Mark Adler <madler@alumni.caltech.edu>

prepare() {
  cd $pkgbase-$pkgver/contrib/minizip
  cp Makefile Makefile.orig
  cp ../README.contrib readme.txt
  autoreconf -fiv
}

build() {
  cd $pkgbase-$pkgver

  CFLAGS+=" -ffat-lto-objects"
  ./configure --prefix=/usr
  make

  cd contrib/minizip
  ./configure --prefix=/usr --enable-static=no
  make
}

check() {
  make test -C $pkgbase-$pkgver

  make -f Makefile.orig test -C $pkgbase-$pkgver/contrib/minizip
}

package_zlib() {
  depends=(glibc)
  provides=(libz.so)

  make install DESTDIR="$pkgdir" -C $pkgbase-$pkgver
  install -D -m644 $pkgbase-$pkgver/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}

package_minizip() {
  pkgdesc='Mini zip and unzip based on zlib'
  depends=(
    glibc
    zlib
  )

  make install DESTDIR="$pkgdir" -C $pkgbase-$pkgver/contrib/$pkgname
  install -D -m644 $pkgbase-$pkgver/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"

  # https://github.com/madler/zlib/pull/229
  rm "$pkgdir/usr/include/minizip/crypt.h"
}

# vim: ts=2 sw=2 et:
